package com.baide.sanguanheyi.swing;

import com.baide.sanguanheyi.sqlite.Content;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @ClassName SelTableModel
 * @Description TODO
 * @Author wangbing
 * @Date 2020/5/19 16:15
 **/
public class SelTableModel extends AbstractTableModel {
    String[] cName = new String[]{"序号", "总运单号", "运单号", "重量", "海关状态", "CT嫌疑", "件数", "品名"};
    List<Content> data;

    public SelTableModel(List<Content> data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return cName.length;
    }

    @Override
    public String getColumnName(int column) {
        return cName[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Content bean = data.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return rowIndex + 1;
            case 1:
                return bean.getVoyageNo();
            case 2://运单号
                return bean.getBarCode();
            case 3:
                return bean.getWeight() == null ? "未获取" : (bean.getWeight() + "g");
            case 4:
                return getOrderString(bean.getCustOrder());
            case 5:
                return bean.getCtOrder() == null ? "未获取" : (bean.getCtOrder().equals("C") ? "放行" : "嫌疑");
            case 6:
                return bean.getPackNo();
            case 7:
                return bean.getMainGName();
        }
        return "";
    }

    private String getOrderString(String order) {
        switch (order) {
            case "0":
                return "放行";
            case "1":
                return "查验";
            case "2":
                return "入库";
            case "3":
                return "放行征税";
            case "4":
                return "退运";
            case "5":
                return "拒识";
            case "6":
                return "退单";
        }
        return "未识别";
    }
}
